package leetcode.array;

/**
 * Created by xinxuchu on 2020/8/16.
 */
public class FindCenterIndex {

    static public int pivotIndex(int[] nums) {
        int sum = 0; int left = 0;
        for (int i = 0; i <nums.length ; i++) {
            sum+=nums[i];
        }
        for (int i = 0; i <nums.length ; i++) {
            left += nums[i];
            if (left-nums[i] == sum-left){
                return i;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{-1,-1,-1,0,1,1};
        System.out.println(pivotIndex(nums));
    }

}
